package io;

import java.io.*;


/**
 * @program: javase
 * @description:
 * @author: lld
 * @create: 2020-11-21 17:12
 **/
public class TestFileReader {
    public static void main(String[] args) {
        FileWriter fileWriter = null;
        FileReader fileReader = null;
        try {
            File file = new File("C:\\Users\\小东\\IdeaProjects\\javase\\other\\src\\io\\新建文本文档.txt");
            File file1 = new File("C:\\Users\\小东\\IdeaProjects\\javase\\other\\src\\io\\old.txt");
            fileReader = new FileReader(file);
            //字符流读文件
            int read = fileReader.read();
            char[] readChar=new char[10];
            while (read != -1) {

                read = fileReader.read(readChar);

            }
            //写入111.js
            fileWriter = new FileWriter(file1, true);
            fileWriter.write(readChar);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {//使用try-catch出错时也关闭
            try {
                if (fileReader != null) {
                    fileReader.close();
                }
                if (fileWriter != null) {
                    fileWriter.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
}
